import { request } from '../../utils/request.js'
Page({
    onLoad: function() {
        let that = this
        request({
            url: '/home/user/coupon',
            method: 'GET',
            success(data) {
                let list = data.data.data
                list = list.filter(item => {
                    return item.status == 3
                })
                that.setData({ couponList: list })
            }
        })
    },
    getCoupon(e) {
        const { id } = e.target.dataset
        let that = this
        request({
            url: '/home/coupon/sign',
            data: {
                coupon_id: id
            },
            success(res) {
                let { couponList } = that.data
                const index = couponList.findIndex(item => {
                    return item.coupon_id == id
                })
                couponList[index].status = 0
                that.setData({ couponList })
                wx.showToast({
                    title: '领取成功',
                    icon: 'success'
                })
            }
        })
    }
})